package com.rui.study.micro.usermanager.config;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

import java.util.HashMap;
import java.util.Map;

@Configuration
@ImportResource(locations = {"WEB-INF/application-context.xml"})
@MapperScan(basePackages = "com.rui.study.micro.usermanager.mapper")
public class ApplicationContextConfig {

//    @Bean(name = "reSubmitFilter")
//    public Filter reSubmitFilter() {
//        return new ReSubmitFilter();
//    }

//    @Bean(name = "securityManager")
//    public DefaultWebSecurityManager securityManager(Collection<Realm> realms) {
//        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
//
//        // 配置realm
//        securityManager.setRealms(realms);
//
//        return securityManager;
//    }

//    @Bean(name = "shiroFilter")
//    public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) {
//        ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
//
//        // SecurityManager
//        shiroFilterFactoryBean.setSecurityManager(securityManager);
//
//        // Filter Chain Definition Map
//        shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap());
//
//        // Filter
//        shiroFilterFactoryBean.setFilters(filters());
//
//        return shiroFilterFactoryBean;
//    }

//    private Map<String,Filter> filters() {
//        Map<String,Filter> map = new HashMap<String, Filter>();
//        map.put("reSubmitFilter", reSubmitFilter());
//        return map;
//    }

    private Map<String,String> filterChainDefinitionMap() {
        Map<String, String> map = new HashMap<String, String>();

        map.put("/user/signUpPage", "anon");
        map.put("/user/signUp","reSubmitFilter");
        map.put("/user/signIn","reSubmitFilter");
        map.put("/administrator/**","authc, roles[administrator]");

        return map;
    }


//    @Bean
//    public Company company() {
//       return CompanyHelper.build();
//    }

}
